﻿using AutoMapper;
using Common.Communal;
using MediatR;
using Scheduling.Api.Write.Application.Command.ShiftCommand;
using Scheduling.Services.Shifts;
using ERP.Domain.Scheduling;

namespace Scheduling.Api.Write.Application.CommandHandlers.ShiftHandler
{
    public class IShiftAddCommandHandler : IRequestHandler<IShiftAddCommand, ApiResult<int>>
    {
        public IShiftAddCommandHandler(IShiftServices shiftServices, IMapper mapper)
        {
            ShiftServices = shiftServices;
            Mapper = mapper;
        }

        public IShiftServices ShiftServices { get; }
        public IMapper Mapper { get; }

        public async Task<ApiResult<int>> Handle(IShiftAddCommand request, CancellationToken cancellationToken)
        {
            var model = Mapper.Map<Shift>(request);
            return await ShiftServices.AddShift(model);
        }
    }
}
